import { createContext, useContext } from "react";
import CouterStore from "./couterStore";
import TodoStore from "./todoStore";

class RootStore {
    constructor() {
        this.couterStore = new CouterStore();
        this.todoStore = new TodoStore();
    }
}

const rootStore = new RootStore();
const RootStoreContext = createContext();
// 通过createContext 想下层组件传递数据
export const RootStoreProvider = ({ children }) => {
    return (
        <RootStoreContext.Provider value={rootStore}>
            {children}
        </RootStoreContext.Provider>
    )
}
// 通过useContext 获取 store 数据
export const useRootStore = ()=>{
    return useContext(RootStoreContext)
}